package apoio;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Toolkit;

public class JDialogSimNao extends JDialog {
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private boolean _valor = false;
	
	/**
	 * Create the dialog.
	 */
	public JDialogSimNao(String titulo, String mensagem) {
		setIconImage(Toolkit.getDefaultToolkit().getImage(JDialogSimNao.class.getResource("/imgs/som.png")));
		setTitle(titulo);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 307, 137);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			JLabel lblMensagem = new JLabel(mensagem);
			contentPanel.add(lblMensagem);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton btnSim = new JButton("Sim");
				btnSim.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						_valor = true;
						setVisible(false); dispose();
					}
				});
				btnSim.setActionCommand("Sim");
				buttonPane.add(btnSim);
				getRootPane().setDefaultButton(btnSim);
			}
			{
				JButton btnNao = new JButton("N\u00E3o");
				btnNao.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						_valor = false;
						setVisible(false); dispose();
					}
				});
				btnNao.setActionCommand("Nao");
				buttonPane.add(btnNao);
			}
		}
	}
	
	public boolean showModalDialog() {
		setModal( true );
		pack();
		setVisible(true);
		return _valor;
	}

}

/*
 JDialogSimNao jdsimnao = new JDialogSimNao("Titulo", "Mensagem");
 System.out.println("jdsimnao.showModalDialog(): " + jdsimnao.showModalDialog());
 */